package view.panels;

import javax.swing.event.ListSelectionEvent;
import model.Turtle;
import controller.TurtleController;

/**
 * This is a class which creates a pane which lists all the active turtles
 * 
 * @author Nathan Klug
 * 
 */
public class TurtleList extends AbstractListPanel<Turtle>
{

    public TurtleList(TurtleController controller)
    {
        super(controller);
    }

    @Override
    public void eventOccurred(ListSelectionEvent event)
    {
        if (!event.getValueIsAdjusting())
        {
            int[] indicesOfSelectedItems = getIndicesOfSelectedItems();
            if (indicesOfSelectedItems.length != 0)
            {
                int whichTurtle = indicesOfSelectedItems[0]; // TODO: Change
                                                             // this behavior to
                                                             // accommodate for
                                                             // selecting
                                                             // multiple
                                                             // turtles?

                PreferencesFrame preferences = new PreferencesFrame(
                        getController(), getListItem(whichTurtle), whichTurtle);
                preferences.setVisible(true);
                clearListSelection();
            }
        }
    }
}
